//
//  OrderDetailBottomOctionView.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/9.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "OrderDetailBottomOctionView.h"
@interface OrderDetailBottomOctionView()
@property (nonatomic,strong) UIButton *cancellBtn;
@property (nonatomic,strong) UIButton *confirmDoneBtn;
@property (nonatomic,strong) UIButton *applyMoneyBackBtn;
@end

@implementation OrderDetailBottomOctionView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, TSScreenWidth, TSScaleW(50));
        [self addSubview:self.cancellBtn];
        [self addSubview:self.confirmDoneBtn];
        [self addSubview:self.applyMoneyBackBtn];
    }
    return self;
}
-(UIButton *)applyMoneyBackBtn{
    if (!_applyMoneyBackBtn) {
        _applyMoneyBackBtn = [TSWLTools allocButtonTitle:@"退款" font:systemFont(TSScaleW(14)) textColor:kSubTxtColor image:nil frame:CGRectMake(TSScaleW(80), TSScaleW(12), TSScaleW(75), TSScaleW(26)) sel:@selector(applyMoneyBackBtnAction:) taget:self];
        [_applyMoneyBackBtn setBorderWithWidth:1 andColor:kGrayTxtColor];
        [_applyMoneyBackBtn setCornerRadius:_applyMoneyBackBtn.height/2.f];
    }
    return _applyMoneyBackBtn;
}
#pragma mark  ---Action
-(void)applyMoneyBackBtnAction:(UIButton *)sender
{
    !self.moneyBackBlock?:self.moneyBackBlock();
}
-(UIButton *)cancellBtn{
    if (!_cancellBtn) {
        _cancellBtn = [TSWLTools allocButtonTitle:@"取消订单" font:systemFont(TSScaleW(13)) textColor:kSubTxtColor image:nil frame:CGRectMake(TSScaleW(180), TSScaleW(12), TSScaleW(75), TSScaleW(26)) sel:@selector(cancellAction:) taget:self];
        _cancellBtn.cornerRadius = _cancellBtn.height/2.f;
        [_cancellBtn setBorderWithWidth:1 andColor:kGrayTxtColor];
    }
    return _cancellBtn;
}
-(void)cancellAction:(UIButton *)sender
{
    !self.cancellBtnBlock?:self.cancellBtnBlock();
}
-(UIButton *)confirmDoneBtn{
    if (!_confirmDoneBtn) {
        _confirmDoneBtn = [TSWLTools allocButtonTitle:@"去付款" font:systemFont(TSScaleW(13)) textColor:kGreenColor image:nil frame:CGRectMake(TSScaleW(20) +_cancellBtn.right, TSScaleW(12), TSScaleW(75), TSScaleW(26)) sel:@selector(confirmDoneBtnAction:) taget:self];
        _confirmDoneBtn.cornerRadius = _cancellBtn.height/2.f;
        [_confirmDoneBtn setBorderWithWidth:1 andColor:kGreenColor];
    }
    return _confirmDoneBtn;
}
-(void)confirmDoneBtnAction:(UIButton *)sender
{
    !self.ensureBtnBlock?:self.ensureBtnBlock();
}
-(void)setModel:(LXRequstOrderDetailModel *)model{
    _model = model;
    _confirmDoneBtn.hidden = YES;
    _cancellBtn.hidden = YES;
    _applyMoneyBackBtn.hidden = YES;
    if (_model.type.integerValue == 0) {
        ///商品订单
        if (_model.state.integerValue == 1 || _model.state.integerValue == 2) {
            if (_model.state.integerValue == 1) {
                _confirmDoneBtn.hidden = NO;
                self.ensureBtnBlock = self.moneyBackBlock;
                [_confirmDoneBtn setTitle:@"退款" forState:(UIControlStateNormal)];
            }
            if (_model.state.integerValue == 2) {
                _applyMoneyBackBtn.hidden = NO;
                [_applyMoneyBackBtn setTitle:@"退款" forState:(UIControlStateNormal)];
            }
        }
    }
    if (_model.state.integerValue == 0) {
        _confirmDoneBtn.hidden = NO;
        self.ensureBtnBlock = self.gotoPayBlock;
        [_confirmDoneBtn setTitle:@"去付款" forState:(UIControlStateNormal)];
        _cancellBtn.hidden = NO;
        self.cancellBtnBlock = self.cancellBlock;
        [_cancellBtn setTitle:@"取消订单" forState:(UIControlStateNormal)];
    }
    if (_model.state.integerValue == 2) {
        _confirmDoneBtn.hidden = NO;
        self.ensureBtnBlock = self.ensureHuoBlock;
        [_confirmDoneBtn setTitle:@"确认收货" forState:(UIControlStateNormal)];
        _cancellBtn.hidden = NO;
        self.cancellBtnBlock = self.seeWuliuBlock;
        [_cancellBtn setTitle:@"查看物流" forState:(UIControlStateNormal)];
    }
    if (_model.state.integerValue == 3) {
        _confirmDoneBtn.hidden = NO;
        self.ensureBtnBlock = self.gotoCommendBlcok;
        [_confirmDoneBtn setTitle:@"去评价" forState:(UIControlStateNormal)];
        _cancellBtn.hidden = NO;
        self.cancellBtnBlock = self.seeWuliuBlock;
        [_cancellBtn setTitle:@"查看物流" forState:(UIControlStateNormal)];
    }
    if (_model.state.integerValue == 4) {
        _confirmDoneBtn.hidden = NO;
        self.ensureBtnBlock = self.deleteOrderBlock;
        [_confirmDoneBtn setTitle:@"删除" forState:(UIControlStateNormal)];
        _cancellBtn.hidden = NO;
        self.cancellBtnBlock = self.seeWuliuBlock;
        [_cancellBtn setTitle:@"查看物流" forState:(UIControlStateNormal)];
    }
    if (_model.state.integerValue == 7) {
        _confirmDoneBtn.hidden = NO;
        self.ensureBtnBlock = self.deleteOrderBlock;
        [_confirmDoneBtn setTitle:@"删除" forState:(UIControlStateNormal)];
    }
}

@end
